<?php

include "../../../lib/start.php";

check_session();
check_permission(DOC_PERM);

$student_id = $_REQUEST['al'];

if(isset($_REQUEST['order']))
	$order = $_REQUEST['order'];
else
	$order = "data";

if(isset($_REQUEST['q']))
	$q = $_REQUEST['q'];
else{
	$q = 0;
}

if(isset($_REQUEST['tipo'])){
	$q_type = "AND tipo = ".$_REQUEST['tipo'];
}
else{
	$q_type = "";
}

switch($q){
	case 0:
		$int_time = "AND data <= NOW()";
		$label = "";
		break;
	case 1:
		$int_time = "AND data < '".format_date($_SESSION['__current_year__']->get_fine_quadrimestre(), IT_DATE_STYLE, SQL_DATE_STYLE, "-")."'";
		$label = ", primo quadrimestre";
		break;
	case 2:
		$int_time = "AND (data BETWEEN '".format_date($_SESSION['__current_year__']->get_fine_quadrimestre(), IT_DATE_STYLE, SQL_DATE_STYLE, "-")."' AND NOW()) ";
		$label = ", secondo quadrimestre";
}

$sel_tipi = "SELECT * FROM tipi_note_disciplinari ORDER BY id_tiponota";
$sel_note = "SELECT note_disciplinari.*, utenti.cognome, utenti.nome, tipi_note_disciplinari.descrizione AS tipo_nota, tipi_note_disciplinari.id_tiponota FROM note_disciplinari, tipi_note_disciplinari, utenti WHERE id_tiponota = tipo AND alunno IS NULL AND classe = ".$_SESSION['__classe__']->get_ID()." AND docente = uid $int_time $q_type ORDER BY $order DESC";
//print $sel_note;
try{
	$res_note = $db->executeQuery($sel_note);
	$res_tipi = $db->executeQuery($sel_tipi);
} catch (MySQLException $ex){
	$ex->redirect();
}

include "notes.html.php";

?>